$(function() {
    $("#loginBtn").click(function() {
        var username = $('#username').val();
        var password = $('#password').val();
        if (username.trim().length == 0) {
            mui.toast('请输入用户名');
            return;
        }
        if (password.trim().length == 0) {
            mui.toast('请输入密码');
            return;
        }
        // console.log(333)
        $.ajax({
            type: 'post',
            url: '/user/login',
            dataType: 'json',
            data: {
                username: username,
                password: password
            },
            success: function(res) {
                if (res.error == 403) {
                    mui.toast(res.message);
                    return;
                }
                if (res.success) {
                    if (location.search.indexOf('reUrl') > -1) {
                        var url = location.search.split('reUrl=')[1];
                        //跳回原页面
                        location.href = url;
                        console.log(1111);
                    } else {
                        //去用户中心 
                        location.href = '../user.html';
                        console.log(2222)
                    }
                }
                console.log(res)
            }
        })
    })
})